home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12410 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: templar.fgi.net!bwendlin
  2. From: bwendlin@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (Bill Wendling)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: File Open Problem - Please provide clues
  5. Date: 31 Mar 1996 08:24:47 GMT
  6. Organization: FGInet, Inc., Springfield, IL
  7. Distribution: world
  8. Message-ID: <4jlfgf$59u@grail.fgi.net>
  9. References: <4jkq8h$1it6@useneta1.news.prodigy.com>
  10. NNTP-Posting-Host: templar.fgi.net
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Steve Bailey inexplicably wrote:
  14.  
  15. } Hi I'm having problems with opening files which are named   
  16. } after simple numbers:                                       
  17. } 2                                                           
  18. } 5, etc.                                                     
  19. } The reason for naming them this way is because I'm writing a
  20. } program in C that increments a number, and then attempts to 
  21. } open the file that's actually named by that number.         
  22. } I get mismatched type errors when using FOPEN:              
  23. }  int num;                                                   
  24. }  filepointer = FOPEN(num,"r");            or                           
  25. }  filepointer = FOPEN("num","r");
  26.  
  27. Try:
  28.     int num;
  29.     char file[255];
  30.  
  31.     sprintf(file, "%d", num);
  32.     filepointer = fopen(file, "r");
  33.  
  34. or something similar to this.
  35.  
  36. } Is there a way to manipulate an integer: store it in integer
  37. } variables, arrays, etc.., but then use that integer to open 
  38. } a file actually named by that integer?..                    
  39. }  I was going to name the files:                             
  40. }   0.txt, 1.txt, 2.txt,                                      
  41.  
  42. With the above example, you could just do:
  43.     sprintf(file, "%d.txt", num);
  44.  
  45. }  and so forth, but this was even trickier with the string   
  46. } concatenating, (attached ".txt" to it) etc.. so the files   
  47. } are named after numbers simply..                            
  48. }                                                             
  49. } any help appreciated.                                       
  50. } Steve
  51.  
  52. --
  53. Bill Wendling            bwendlin@fgi.net 
  54. GCS/M/S d s-:+ a? C++++$ UL++>++++ P+++>+++++ L+++>+++++ E--- W-- N++ !o
  55. !K w--- O M-- !V PS+++@ PE- Y !PGP t+++(*) 5-- X- R++ tv--- b+++ DI++++
  56. !D G+ e++>+++++ h(++) !r !y+
  57.